<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html>
<head>
{include file='header.tpl' JS=$smarty.const.BAOGG_JS CSS=$smarty.const.BAOGG_CSS}        

<script type="text/javascript"> 
	var  LANG={$LANG};

	Ext.onReady(function(){
		Ext.QuickTips.init();
		
		var store = Ext.create('Ext.data.TreeStore', {
			proxy : {
				type : 'ajax',
				url : '{$form_url}'
			},
			listeners: {
				'load':function( self,  records,  successful,  options ){
					{foreach $arr_op_in_resource as $op_in_resource}
					    self.getNodeById("{$op_in_resource}").set('checked',true);
					{/foreach}

					
				}
			}
		});

		var tree = Ext.create('Ext.ux.TreePanel', {
			id : 'treePanel',
			store : store,
			rootVisible : false,
			useArrows : true,
			region:'center',
			frame : true,
			title : '{$resource_name}',
			height :600,//minH			
			renderTo: 'tree1',
			//renderTo: 'tree1',						
			dockedItems : [ {
				xtype : 'toolbar',
				items :[ {
					text : '{$LANG.save}',
					handler : function() {
						var records = tree.getView().getChecked(), names = [];

						Ext.Array.each(records, function(rec) {

							names.push(rec.get('id'));
						});
						
						Ext.Ajax.request({
							url: '{$edit_url}',
							method:'POST',
							params:{ ids:names.join(',') },
							success: function(response, opts) {
							  var obj = Ext.decode(response.responseText);
							  if(obj.success){
								top.Ext.ux.ShowSuccess(obj.msg);

							  }else{
								top.Ext.ux.ShowError(obj.msg);
							  }
							},
							failure: function(response, opts) {
							  console.log('server-side failure with status code ' + response.status);
							}
						});
						
					}
				},
               { text: 'Expand All',
                handler: function(){
                    Ext.getCmp("treePanel").expandAll();
                }
            }, {
                text: 'Collapse All',
                handler: function(){
                    Ext.getCmp("treePanel").collapseAll();
                }
            }]
			} ]
		});
		
			
    		
		 /*
		 Ext.getCmp('treePanel').getStore().getNodeById("8_list").set('checked',false)*/
		 Ext.create('Ext.container.Viewport', {
			layout: 'border',
			renderTo: Ext.getBody(),
			items: tree				
                });
	});
</script>

</head>
<body>
  
       
<div id="tree1"></div>


</body>
</html>